package cn.linpq.frame;
import cn.linpq.menu.MineMenuBar;
import cn.linpq.panel.MineField;
import cn.linpq.panel.MineState;
import cn.linpq.util.Tools;

import javax.swing.*;
import java.awt.*;

/**
 * Desc : 扫雷顶层容器
 * ClassName : cn.linpq.frame.MineFrame
 * @author : 林鹏群
 * @date : 2022/12/12 10:56
 */
public class MineFrame extends JFrame {
    private MineMenuBar mineMenuBar;
    private MineField mineField;
    private MineState mineState;
    /**
     * 开局
     */
    public MineFrame(){
        //设置标题
        this.setTitle("扫雷，by：林鹏群 20221212");
        //设置初始化位置
        this.setLocation(500,500);
        //设置关闭事件 EXIT_ON_CLOSE
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        //设置图标
        this.setIconImage(Tools.logo);
        //设置布局
        this.setLayout(new BorderLayout());
        //初始化菜单栏
        this.mineMenuBar = new MineMenuBar(this);
        //添加菜单栏
        this.setJMenuBar(mineMenuBar);
        //初始化状态栏
        this.mineState = new MineState(this);
        //添加状态栏
        this.add(mineState, BorderLayout.NORTH);
        //初始化雷区
        this.mineField = new MineField(this);
        //添加雷区
        this.add(mineField);
        //设置关闭改变大小
        this.setResizable(false);
        //设置窗体可见
        this.setVisible(true);
        //设置大小适应
        this.pack();
    }
    /**
     * 重新开始
     */
    public void restart(){
        //移除状态栏
        this.remove(mineState);
        //移除雷区
        this.remove(mineField);
        //初始化状态栏
        this.mineState = new MineState(this);
        //添加状态栏
        this.add(mineState, BorderLayout.NORTH);
        //初始化雷区
        this.mineField = new MineField(this);
        //添加雷区
        this.add(mineField);
        //设置大小适应
        this.pack();
    }

    public MineMenuBar getMineMenuBar() {
        return mineMenuBar;
    }

    public void setMineMenuBar(MineMenuBar mineMenuBar) {
        this.mineMenuBar = mineMenuBar;
    }

    public MineField getMineField() {
        return mineField;
    }

    public void setMineField(MineField mineField) {
        this.mineField = mineField;
    }

    public MineState getMineState() {
        return mineState;
    }

    public void setMineState(MineState mineState) {
        this.mineState = mineState;
    }

    public static void main(String[] args) {
        new MineFrame();
    }
}
